﻿if (F.Window) {
    $.extend(F.Window.prototype, {
    });

    //动画
    let _show = F.Window.prototype.show;
    let _hide = F.Window.prototype.hide;
    //进入动画
    F.Window.prototype.inCss = "fadeInDown";//zoomIn fadeInDown
    //退出动画
    F.Window.prototype.outCss = "fadeOutDown";//fadeOutDown zoomOut

    //默认开启动画
    F.Window.prototype.animateCss = true;

    //这里需要重写隐藏方法
    $.extend(F.Window.prototype, {
        initListeners: {
            beforrender() {
                const t = this;
                Object.defineProperty(t, "inCss",
                    {
                        get: function () {
                            if (t.maximized) return "zoomIn";
                            return "fadeInDown";
                        }
                    });
                Object.defineProperty(t, "outCss",
                    {
                        get: function () {
                            if (t.maximized) return "zoomOut";
                            return "fadeOutDown";
                        }
                    });
            }
        },
        show() {
            const t = this;
            t.el.css('animation-duration', "0.3s");
            _show.apply(t, arguments);
            //需要将display还原
            t.animateCss && t.el.animateCss(t.inCss, () => {
                t.el.removeClass(t.inCss);
                t.el.css('opacity', "1");
            });
        },
        hide() {
            const t = this;
            //在动画执行后 再执行原始方法 因为执行后有回调 也可以用延迟
            t.el.css('animation-duration', "0.3s");
            t.animateCss && (t.target != "_top" || t.el.hasClass('f-messagebox-notify')) && t.el.animateCss(t.outCss, () => {
                //回调 删除 动画的css
                t.el.removeClass(t.outCss);
                //需要将display还原
                t.el.css('display', "none");
                //继续执行
                _hide.apply(this, [...arguments]);
            });
            if (!t.animateCss || (t.target == "_top" && !t.el.hasClass('f-messagebox-notify'))) {
                _hide.apply(this, [...arguments]);
            }
        }
    });
}

if (F.MessageBox) {
    const beforRender = F.MessageBox.prototype.initListeners.beforrender;
    const beforehide = F.MessageBox.prototype.initListeners.beforehide;
    $.extend(F.MessageBox.prototype.initListeners, {
        beforrender: function () {
            let t = this;
            beforRender && beforRender.apply(t);
            t.el.css('animation-duration', "0.3s");
            //需要将display还原
            t.animateCss && t.el.animateCss(t.inCss, () => {
                t.el.removeClass(t.inCss);
                t.el.css('opacity', "1");
            });
        },
    });
}


//控件基类
if (F.Component) {
    $.extend(F.Component.prototype, {
    });

    //在render之前触发一个beforrender事件
    let trigger = F.Component.prototype.trigger.name;
    Reflect.defineProperty(F.Component.prototype, trigger, {
        value: new Proxy(F.Component.prototype[trigger], {
            apply(target, thisArg, args) {
                if (args[0] == "render") {
                    thisArg.trigger("beforrender", []);
                }
                return Reflect.apply(target, thisArg, [...args]);
            }
        }),
    });

    //在init前注册initListeners事件 提供全局init前注册
    let doInit = F.Component.prototype.doInit.name;
    Reflect.defineProperty(F.Component.prototype, doInit, {
        value: new Proxy(F.Component.prototype[doInit], {
            apply(target, thisArg, args) {
                for (var listen in thisArg.initListeners) {
                    thisArg.on(listen, thisArg.initListeners[listen]);
                }
                return Reflect.apply(target, thisArg, [...args]);
            }
        }),
    });
}
